#!/bin/bash

#
#	$Id: tlbimp,v 1.2 2008-02-20 18:48:57 mayhewn Exp $
#
#	Execute tlbimp on remote win32 machine
#
#	Mark Strobert - 2008-02-08
# 
# COM Support Library helper script
# Copyright (C) 2007 SIL International
# 
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
# 
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
# 
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
#
# http://www.gnu.org/licenses/lgpl.html
# 

if [ $# -lt 3 ]; then
	echo Usage: $0 remote_host IFoo.tlb /out:IFooInterop.dll [tlbimp args]
	exit 1
fi

REMOTE_HOST=$1
INFILE="$2"
shift

# Choose temporary directory on remote machine
DIR=$(ssh "$REMOTE_HOST" "mktemp -dt")
if [ -z "$DIR" ]
  then echo $(basename "$0"): Error choosing temporary directory on remote host.
  exit 1
fi

CMD="cd \"$DIR\" && tlbimp $*"
STEM=$(basename "$INFILE" .tlb)

scp "$INFILE" "$REMOTE_HOST:$DIR"/ && 
	ssh "$REMOTE_HOST" "$CMD" && 
	scp "$REMOTE_HOST:$DIR"/${STEM}Interop.dll . ||
	(echo $(basename "$0"): Error communicating with remote host.; exit 1)
